import { Config } from "../../types/config";
import { normalize, resolve, sep } from "path";
import { cwd } from "process";
import { CONFIG } from "../../utils/config";
import { resolveWorkspace } from "../../utils/common";
import { createHash } from "crypto";

export function resolveOptionUploadList(config: Pick<Config, "uploadList">) {
    const { uploadList } = config;

    return uploadList.map((upload) => {
        const fileList = upload.fileList.map((file) => {
            const localPath = resolveWorkspace(file.localPath);
            const remotePath = normalize(file.remotePath);

            return {
                id: createHash("md5").update(localPath).digest("hex"),
                remotePath,
                localPath,
                localFilename: localPath.split(sep).pop()!,
                remoteFilename: remotePath.split(sep).pop()!,
            };
        });
        return {
            ...upload,
            fileList,
        };
    });
}
